package au.com.mason.propertyTracker.editor;

import java.beans.PropertyEditorSupport;

public class EnumEditor extends PropertyEditorSupport {
	 private Class clazz;
	 
	 public EnumEditor(Class clazz) {
	  this.clazz = clazz;
	 }
	 
	 public String getAsText() {
	  return (getValue() == null ? "" : ((Enum)(getValue())).name());
	 }
	 
	 public void setAsText(String text) throws IllegalArgumentException {
		 if (text.equals("Not Selected")) setValue("");
		 else setValue(Enum.valueOf(clazz, text));
	 }
}
